package com.suray.rgv.son.data;

import com.suray.basic.wcs.utils.typedef.Byte;
import com.suray.basic.wcs.utils.typedef.Word;

public class ModbusWriteRecMessage extends ModbusBaseMessage {
    public ModbusWriteRecMessage() {
        super("子车modbus写入返回", true);
        baseDatas.add(new Byte("slaveAddr", "从机地址"));
        baseDatas.add(new Byte("funcCode", "功能代码"));
        baseDatas.add(new Word("startAddr", "数据起始地址"));
        baseDatas.add(new Word("dataLength", "寄存器个数"));
        baseDatas.add(new Word("crc", "校验码"));
    }

    public int getSlaveAddr() {
        return getValue("slaveAddr");
    }

    public int getStartAddr() {
        return getValue("startAddr");
    }

    public int getDataLength() {
        return getValue("dataLength");
    }

    public int getCrc() {
        return getValue("crc");
    }

    public void validateMessage(int slaveAddr, int startAddr, int dataLength, int crc) {
        if (getSlaveAddr() != slaveAddr) {
            throw new RuntimeException("从机地址错误:" + getSlaveAddr());
        }
        if (getStartAddr() != startAddr) {
            throw new RuntimeException("起始地址错误:" + getStartAddr());
        }
        if (getDataLength() != dataLength) {
            throw new RuntimeException("数据长度错误:" + getDataLength());
        }
        if (getCrc() != crc) {
            throw new RuntimeException("crc错误:" + getCrc() + "--" + crc);
        }
    }
}
